/*
package security.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import security.entity.Menu;
import security.entity.Role;
import security.entity.Users;
import security.mapper.UserMapper;

import java.util.ArrayList;
import java.util.List;

*/
/**
 * @program: check-repetition
 * @description:
 * @author: hjk
 * @create: 2021-07-16 15:53
 **//*

@Slf4j
@Service
public class LoginService implements UserDetailsService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("进入登录。。。。。。。。。。。。。=============");
        QueryWrapper<Users> wrapper = new QueryWrapper();
        wrapper.eq("username",username);
        Users users = userMapper.selectOne(wrapper);
        if(users == null) {
            throw new UsernameNotFoundException("用户名不存在！");
        }
        System.out.println(users);
        List<Menu> menus = userMapper.selectMenuByUserId(users.getId());
        List<Role> roles = userMapper.selectRoleByUserId(users.getId());

        List<GrantedAuthority> grantedAuthorityList = new ArrayList<>();
        // 处理角色
        roles.forEach(role -> {
            SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_" + role.getName());
            grantedAuthorityList.add(simpleGrantedAuthority);
        });
        // 处理权限
        menus.forEach(menu -> {
            grantedAuthorityList.add(new SimpleGrantedAuthority(menu.getPermission()));
        });


        //List<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList("role");
        //return new org.springframework.security.core.userdetails.User(users.getUsername(), new BCryptPasswordEncoder().encode(users.getPassword()),auths);
        return new User(username,users.getPassword(),grantedAuthorityList);
    }
}
*/
